package site.zhouinfo.scanfiletime;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhou
 * @create 2017-10-18 23:56
 * @email zhouinfo@qq.com
 * @blog blog.zhouinfo.site
 */
public class FileInfo implements Comparable<FileInfo> {

    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private String fileName;
    private long lastModified;

    public FileInfo() {
    }

    public FileInfo(String fileName, long lastModified) {
        this.fileName = fileName;
        this.lastModified = lastModified;
    }

    /**
     * 把long 转换成 日期 再转换成String类型
     */
    public static String transferLongToDate(Long millSec) {
        Date date = new Date(millSec);
        return sdf.format(date);
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public long getLastModified() {
        return lastModified;
    }

    public void setLastModified(long lastModified) {
        this.lastModified = lastModified;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append(transferLongToDate(lastModified)).append("\t\t");
        sb.append(fileName).append('\n');
        return sb.toString();
    }

    @Override
    public int compareTo(FileInfo f) {
        if (lastModified <= f.lastModified) {
            return 1;
        } else {
            return -1;
        }
    }
}
